<?php

namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\UserWithdrawApply;

/**
 * 提现申请
 */
class Withdraw extends Api
{
    /**
     * MoneyLog模型对象
     * @var \app\common\model\UserWithdrawApply
     */
    protected $model = null;
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new UserWithdrawApply();
    }

    /**
     * 提现申请
     */

    public function add(){
        $money = input('post.money',0);
        if($money <=0){
            $this->error('提现金额不合法');
        }
        $collection_name = input('post.collection_name','');
        $zfb             = input('post.zfb');
        if(!$collection_name || !$zfb){
            $this->error('缺少必填参数');
        }
        if($this->auth->money < $money){
            $this->error('您没有那么多佣金可提现');
        }
        $params['user_id']         = $this->auth->id;
        $params['collection_name'] = $collection_name;
        $params['zfb']             = $zfb;
        $params['money']           = $money;
        $model = new \app\common\model\User();
        $model->money(-$money,$this->auth->id,'提现申请');
        $this->model->create($params);
        $this->success('ok');
    }

}
